﻿using System;
using UnityEngine;
using UnityEngine.UI;

namespace Studio
{
	// Token: 0x020005B1 RID: 1457
	public class MapCtrl : Singleton<MapCtrl>
	{
		// Token: 0x17000481 RID: 1153
		// (set) Token: 0x0600250C RID: 9484 RVA: 0x000DC4C4 File Offset: 0x000DA6C4
		public bool active
		{
			set
			{
				base.gameObject.SetActive(value);
				if (value)
				{
					this.UpdateUI();
				}
			}
		}

		// Token: 0x0600250D RID: 9485 RVA: 0x000DC4E0 File Offset: 0x000DA6E0
		public void UpdateUI()
		{
			this.SetInputTextPos();
			this.SetInputTextRot();
		}

		// Token: 0x0600250E RID: 9486 RVA: 0x000DC4F0 File Offset: 0x000DA6F0
		public void Reflect()
		{
			GameObject objMap = Singleton<MapCtr>.Instance.objMap;
			if (objMap == null)
			{
				return;
			}
			Transform transform = objMap.transform;
			transform.localPosition = Singleton<Studio>.Instance.sceneInfo.caMap.pos;
			transform.localRotation = Quaternion.Euler(Singleton<Studio>.Instance.sceneInfo.caMap.rot);
			this.UpdateUI();
		}

		// Token: 0x0600250F RID: 9487 RVA: 0x000DC55C File Offset: 0x000DA75C
		public void OnEndEditPos(int _target)
		{
			float num = this.InputToFloat(this.inputPos[_target]);
			Vector3 pos = Singleton<Studio>.Instance.sceneInfo.caMap.pos;
			if (pos[_target] != num)
			{
				Vector3 vector = pos;
				pos[_target] = num;
				Singleton<Studio>.Instance.sceneInfo.caMap.pos = pos;
				Singleton<UndoRedoManager>.Instance.Push(new MapCommand.MoveEqualsCommand(new MapCommand.EqualsInfo
				{
					newValue = pos,
					oldValue = vector
				}));
			}
			this.SetInputTextPos();
		}

		// Token: 0x06002510 RID: 9488 RVA: 0x000DC5E8 File Offset: 0x000DA7E8
		public void OnEndEditRot(int _target)
		{
			float num = this.InputToFloat(this.inputRot[_target]) % 360f;
			Vector3 rot = Singleton<Studio>.Instance.sceneInfo.caMap.rot;
			if (rot[_target] != num)
			{
				Vector3 vector = rot;
				rot[_target] = num;
				Singleton<Studio>.Instance.sceneInfo.caMap.rot = rot;
				Singleton<UndoRedoManager>.Instance.Push(new MapCommand.RotationEqualsCommand(new MapCommand.EqualsInfo
				{
					newValue = rot,
					oldValue = vector
				}));
			}
			this.SetInputTextRot();
		}

		// Token: 0x06002511 RID: 9489 RVA: 0x000DC678 File Offset: 0x000DA878
		private float InputToFloat(InputField _input)
		{
			float num = 0f;
			return (!float.TryParse(_input.text, out num)) ? 0f : num;
		}

		// Token: 0x06002512 RID: 9490 RVA: 0x000DC6A8 File Offset: 0x000DA8A8
		private void SetInputTextPos()
		{
			Vector3 pos = Singleton<Studio>.Instance.sceneInfo.caMap.pos;
			for (int i = 0; i < 3; i++)
			{
				this.inputPos[i].text = pos[i].ToString("0.000");
			}
		}

		// Token: 0x06002513 RID: 9491 RVA: 0x000DC700 File Offset: 0x000DA900
		private void SetInputTextRot()
		{
			Vector3 rot = Singleton<Studio>.Instance.sceneInfo.caMap.rot;
			for (int i = 0; i < 3; i++)
			{
				this.inputRot[i].text = rot[i].ToString("0.000");
			}
		}

		// Token: 0x06002514 RID: 9492 RVA: 0x000DC758 File Offset: 0x000DA958
		private void OnBeginDragTrans()
		{
			this.oldValue = Singleton<Studio>.Instance.sceneInfo.caMap.pos;
			this.transMap = Singleton<MapCtr>.Instance.objMap.transform;
		}

		// Token: 0x06002515 RID: 9493 RVA: 0x000DC78C File Offset: 0x000DA98C
		private void OnEndDragTrans()
		{
			Singleton<UndoRedoManager>.Instance.Push(new MapCommand.MoveEqualsCommand(new MapCommand.EqualsInfo
			{
				newValue = Singleton<Studio>.Instance.sceneInfo.caMap.pos,
				oldValue = this.oldValue
			}));
			this.transMap = null;
		}

		// Token: 0x06002516 RID: 9494 RVA: 0x000DC7DC File Offset: 0x000DA9DC
		private void OnDragTransXZ()
		{
			Vector3 direction = new Vector3(Input.GetAxis("Mouse X"), 0f, Input.GetAxis("Mouse Y"));
			Singleton<Studio>.Instance.sceneInfo.caMap.pos += this.transMap.TransformDirection(direction);
		}

		// Token: 0x06002517 RID: 9495 RVA: 0x000DC834 File Offset: 0x000DAA34
		private void OnDragTransY()
		{
			Vector3 direction = new Vector3(0f, Input.GetAxis("Mouse Y"), 0f);
			Singleton<Studio>.Instance.sceneInfo.caMap.pos += this.transMap.TransformDirection(direction);
		}

		// Token: 0x06002518 RID: 9496 RVA: 0x000DC888 File Offset: 0x000DAA88
		private void OnBeginDragRot()
		{
			this.oldValue = Singleton<Studio>.Instance.sceneInfo.caMap.rot;
		}

		// Token: 0x06002519 RID: 9497 RVA: 0x000DC8A4 File Offset: 0x000DAAA4
		private void OnEndDragRot()
		{
			Singleton<UndoRedoManager>.Instance.Push(new MapCommand.RotationEqualsCommand(new MapCommand.EqualsInfo
			{
				newValue = Singleton<Studio>.Instance.sceneInfo.caMap.rot,
				oldValue = this.oldValue
			}));
		}

		// Token: 0x0600251A RID: 9498 RVA: 0x000DC8F0 File Offset: 0x000DAAF0
		private void OnDragRotX()
		{
			Vector3 rot = Singleton<Studio>.Instance.sceneInfo.caMap.rot;
			rot.x = (rot.x + Input.GetAxis("Mouse Y")) % 360f;
			Singleton<Studio>.Instance.sceneInfo.caMap.rot = rot;
		}

		// Token: 0x0600251B RID: 9499 RVA: 0x000DC948 File Offset: 0x000DAB48
		private void OnDragRotY()
		{
			Vector3 rot = Singleton<Studio>.Instance.sceneInfo.caMap.rot;
			rot.y = (rot.y + Input.GetAxis("Mouse X")) % 360f;
			Singleton<Studio>.Instance.sceneInfo.caMap.rot = rot;
		}

		// Token: 0x0600251C RID: 9500 RVA: 0x000DC9A0 File Offset: 0x000DABA0
		private void OnDragRotZ()
		{
			Vector3 rot = Singleton<Studio>.Instance.sceneInfo.caMap.rot;
			rot.z = (rot.z + Input.GetAxis("Mouse X")) % 360f;
			Singleton<Studio>.Instance.sceneInfo.caMap.rot = rot;
		}

		// Token: 0x0600251D RID: 9501 RVA: 0x000DC9F8 File Offset: 0x000DABF8
		protected override void Awake()
		{
			if (!base.CheckInstance())
			{
				return;
			}
			MapDragButton mapDragButton = this.mapDragButton[0];
			mapDragButton.onBeginDragFunc = (Action)Delegate.Combine(mapDragButton.onBeginDragFunc, new Action(this.OnBeginDragTrans));
			MapDragButton mapDragButton2 = this.mapDragButton[0];
			mapDragButton2.onDragFunc = (Action)Delegate.Combine(mapDragButton2.onDragFunc, new Action(this.OnDragTransXZ));
			MapDragButton mapDragButton3 = this.mapDragButton[0];
			mapDragButton3.onEndDragFunc = (Action)Delegate.Combine(mapDragButton3.onEndDragFunc, new Action(this.OnEndDragTrans));
			MapDragButton mapDragButton4 = this.mapDragButton[1];
			mapDragButton4.onBeginDragFunc = (Action)Delegate.Combine(mapDragButton4.onBeginDragFunc, new Action(this.OnBeginDragTrans));
			MapDragButton mapDragButton5 = this.mapDragButton[1];
			mapDragButton5.onDragFunc = (Action)Delegate.Combine(mapDragButton5.onDragFunc, new Action(this.OnDragTransY));
			MapDragButton mapDragButton6 = this.mapDragButton[1];
			mapDragButton6.onEndDragFunc = (Action)Delegate.Combine(mapDragButton6.onEndDragFunc, new Action(this.OnEndDragTrans));
			for (int i = 0; i < 3; i++)
			{
				MapDragButton mapDragButton7 = this.mapDragButton[2 + i];
				mapDragButton7.onBeginDragFunc = (Action)Delegate.Combine(mapDragButton7.onBeginDragFunc, new Action(this.OnBeginDragRot));
				MapDragButton mapDragButton8 = this.mapDragButton[2 + i];
				mapDragButton8.onEndDragFunc = (Action)Delegate.Combine(mapDragButton8.onEndDragFunc, new Action(this.OnEndDragRot));
			}
			MapDragButton mapDragButton9 = this.mapDragButton[2];
			mapDragButton9.onDragFunc = (Action)Delegate.Combine(mapDragButton9.onDragFunc, new Action(this.OnDragRotX));
			MapDragButton mapDragButton10 = this.mapDragButton[3];
			mapDragButton10.onDragFunc = (Action)Delegate.Combine(mapDragButton10.onDragFunc, new Action(this.OnDragRotY));
			MapDragButton mapDragButton11 = this.mapDragButton[4];
			mapDragButton11.onDragFunc = (Action)Delegate.Combine(mapDragButton11.onDragFunc, new Action(this.OnDragRotZ));
		}

		// Token: 0x0400259B RID: 9627
		[SerializeField]
		private InputField[] inputPos;

		// Token: 0x0400259C RID: 9628
		[SerializeField]
		private InputField[] inputRot;

		// Token: 0x0400259D RID: 9629
		[SerializeField]
		private MapDragButton[] mapDragButton;

		// Token: 0x0400259E RID: 9630
		private Vector3 oldValue = Vector3.zero;

		// Token: 0x0400259F RID: 9631
		private Transform transMap;
	}
}
